import {useEffect, useState} from "react";
import {RespSysSettingDataType, getOrgTreeData} from "../../api";

export const useTreeData = () => {
    const [loading, setLoading] = useState(false);
    const [treeData, setTreeData] = useState<RespSysSettingDataType.DeptTreeNode[]>([]);

    useEffect(() => {
        fetchOrgTreeData();
    }, []);

    const fetchOrgTreeData = (params:{deptName?: string} = {}) =>{
        setLoading(true);
        getOrgTreeData(params).then((resp) => {
            setTreeData(resp.data);
            setLoading(false);
        })
    }

    return {loading, treeData, fetchOrgTreeData};
}
